<?php
/*------------------------------------------------------------------------
# company - company management 
# @author    pipapai.com
-------------------------------------------------------------------------*/
defined('_JEXEC') or die;
// disable core styles to avoid bs conflict 
OC_Util::$core_styles = array();

if(isDevMode()) {
   OCP\Util::addStyle('company', 'company');
   OCP\Util::addScript('multiselect');
   OCP\Util::addScript('company', 'subaccounts');
} else {
   OCP\Util::addStyle('static', 'company');
   OCP\Util::addScript('static', 'apps/company.subaccounts.min');
}


OCP\App::setActiveNavigationEntry('company_settings');

$lang = PFactory::getLanguage();
$lang->load("com_jobs", JPATH_SITE, "zh-CN");

$userQuota = PCompanyHelper::getUserQuota();
?>

<script type="text/javascript" src="<?php print_unescaped(OC_Helper::linkTo('company/js', 'company.php'));?>"></script>

<div class="hr_inner_navigate clearfix">
	<ul class="clearfix">
      <?php PCompanyHelper::showNavigationMenu($_['masteruser'], 'subaccounts');?>
   </ul>
</div>

<div class="hr_company_set" style="padding:20px 0 30px 0;">
   <div class="subaccounts_top">
      <span>您可以创建公司子账号来协同管理</span>
      <span id="createuserSpan" class="btnwraper"><a href="javascript:;" class="ppp_bluebtn createsubbtn">创建子账号</a></span>
      <?php if($_['masteruser'] && $userQuota['quota']['subaccount_max'] != 'any'): ?>
      <?php 
      $upgradeTips = '';
      if ($userQuota['qtype'] == 'free' && $userQuota['num_subaccounts'] < $userQuota['quota']['subaccount_max']) {
         $upgradeTips = '免费用户仅可创建'.$userQuota['quota']['subaccount_max'].'个子账号，请及时升级账号。';
      } elseif ($userQuota['num_subaccounts'] >= $userQuota['quota']['subaccount_max']) {
         $upgradeTips = '您的子账号创建数已达上限，请及时升级账号。';
      }
      ?>
         <?php if (!empty($upgradeTips) && PCompanyHelper::checkQuotaEnable()): ?>
         <span class="yellowcolor"><?=$upgradeTips?><a href="<?=OC_Helper::linkToRoute('company_quota')?>">立即升级</a></span>
         <?php endif; ?>
      <?php endif; ?>
   </div>
   
   <div id="newuserDiv" class="form-horizontal editaccount_section" style="display:none;">
     <form id="newuser" name="newuser" class="saveuser" method="post" action="<?=OC_Helper::linkTo('company','ajax/createsubaccount.php')?>" autocomplete="off">
     <div class="control-group">
       <label class="control-label key" for=""><em class="redstar">*</em> 姓<em class="nbspem"></em>名：</label>
       <div class="controls">
         <input type="text" name="displayname" placeholder="">
       </div>
     </div>
     <div class="control-group">
       <label class="control-label" for=""><em class="redstar">*</em> 登录邮箱：</label>
       <div class="controls">
         <input type="text" name="username" placeholder="">
         <!-- <span>rong****saf@yaoo.com</span> -->
       </div>
     </div>
     <div class="control-group">
       <label class="control-label" for=""><em class="redstar">*</em> 密<em class="nbspem"></em>码：</label>
       <div class="controls">
         <input type="password" name="password">
       </div>
     </div>
     <div class="control-group">
       <label class="control-label" for="">备<em class="nbspem"></em>注：</label>
       <div class="controls">
         <input type="text" name="note" placeholder="32个字符以内，如：本公司招聘负责人" style="width:320px;" >
       </div>
     </div>
     <div class="control-group">
       <label class="control-label" for=""><em class="redstar">*</em> 权<em class="nbspem"></em>限：</label>
       <div class="controls">
         <div class="purview_each">
            <label class="checkbox">
               <input type="checkbox" checked disabled> <b>查看职位和简历</b>
            </label>
         </div>
         <div class="purview_each">
            <label class="checkbox purviewcheckbox_first" style="position:relative;">
               <input type="checkbox" name="permission[]" value="<?=PERMISSION_JOB_CRUD?>"> <b>发布职位</b> <em class="graycolor">(可创建新职位，并可管理创建的职位)</em>
            </label>
         </div>
         <div class="purview_each" style="border-bottom:0px; margin-bottom:0px;">
            <label class="checkbox purviewcheckbox_second">
               <input type="checkbox" name="permission[]" value="" class="jobmanage"> <b>管理职位</b> <em class="graycolor">(可管理全部或指定职位，包括职位同步、关闭、修改、招聘设置及简历)</em>
            </label>
         </div>
         <div class="purview_eachlast medium graycolor">
            <label class="radio inline">
               <input type="radio" disabled name="radio1" value="<?=PERMISSION_JOB_ADMIN_ALL?>" class="alljobs"> 全部职位 <em style="color:#ff6600;" class="yellow" style="display:none;">(包括以后创建的职位)</em>
            </label>
            <label class="radio inline">
               <input type="radio" disabled name="radio1" value="<?=PERMISSION_JOB_ADMIN_ASSIGNED?>" class="partjobs"> 指定职位 <em style="color:#ff6600;" class="yellow" style="display:none;">(包括该子账号创建的职位)</em><a href="javascript:;" class="clicktochange assignjobs showlist" style="display:none;">修改</a>
            </label>
         </div>
         <div class="purposlistbox" style="display:none;">
            <i style="left:260px;"></i>
            <table width="100%" border="0" cellpadding="0" cellspacing="0" class="jobtable">
            </table>
         </div>
       </div>
     </div>
     <div class="control-group">
       <div class="controls">
         <span class="lastactionbtn"><a href="javascript:;" class="ppp_bluebtn sure">确认</a></span>
         <span class="lastactionbtn"><a href="javascript:;" class="ppp_whitebtn cancel">取消</a></span>
         <span class='error server'></span>
         <input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken">
       </div>
     </div>
     </form>
   </div>
   
   <div id="edituserDiv" class="form-horizontal editaccount_section" style="display:none;">
   </div>
   
   <div id="subaccountList" class="subaccounts_tablelist medium">
      <?=($_['userslist'])?>
   </div>
   
   
   <!-- 下面注释的是老代码，留开发使用 -->
   <?php if(0): ?>
   <div class="subaccountsform">
      <div class="tips normal">
         您可以创建公司的子账号和分组来协同管理您公司简历。创建完成后，您可以一键点击将优秀的简历分享给子账号或一个分组。</br/>
         没有子账号的分组将会被系统自动删除(系统提供的分组除外)。
      </div>

      <form class="form-inline" id="newuser">
         <div class='text-info'>输入姓名，登录邮箱和密码，点击创建生成公司子账号：</div>
         <input type="text" class="input-small" name="displayname" id="newdisplayname" placeholder="姓名">
         <input type="text" class="input-medium" name="username" id="newusername" placeholder="登录邮箱">
         <input type="password" class="input-small" name="password" id="newuserpassword" title="密码长度6～15位，字母区分大小写" placeholder="密码">
         <select  class="groupsselect" id="newusergroups" multiple="multiple">
         <?php foreach($_["groups"] as $group): ?>
         <option data-admin="<?php p($group->isadmin ? 1 : 0); ?>"  value="<?php p($group->groupname);?>">
            <?php p($group->groupname);?>
         </option>
         <?php endforeach;?>
         </select>
         <input type="submit" class="btn btn-info" value="创建" />
         <span class='error server'></span>
         <input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken">
      </form>

      <?php
         $hidetable = false;
         if(empty($_["users"])) {
            $hidetable = true; 
            $fake = new JObject();
            $fake->uid=$fake->displayname=$fake->groups='';
            $_["users"][] = $fake;
         }
      ?>

      <div class="subaccountlist">
      <table id='subaccountList' class="table table-striped table-hover" <?php echo ($hidetable ? 'style="display:none"' : ''); ?>             data-groups="<?php p(implode(',', $allGroups));?>">
      <thead>
      <tr>
         <th id="headerDisplayName">姓名</th>
         <th id='headerEmail'>登录邮箱</th>
         <th id="headerPassword">密码</th>
         <th id="headerGroups">分组</th>
      </tr>
      </thead>
      <tbody>
      <?php foreach($_["users"] as $user): ?>
      <tr <?php echo ($hidetable ? 'style="display:none"' : ''); ?> data-uid="<?php p($user->uid) ?>"
         data-displayname="<?php p($user->displayname) ?>">
         <td class="displayname"><span><?php p($user->displayname); ?></span>
             <img class="svg action" src="<?php p(image_path('core', 'actions/rename.svg'))?>"
              alt="修改姓名" title="修改姓名"/>
         </td>
         <td class="username"><span title="登录邮箱不可以更改"><?php p($user->uid); ?></span></td>
         <td class="password"><span>●●●●●●●</span> 
            <img class="svg action"  src="<?php print_unescaped(image_path('core', 'actions/rename.svg'))?>"
              alt="修改密码" title="修改密码"/>
         </td>
         <td class="groups">
            <select class="groupsselect"
            data-uid="<?php p($user->uid) ;?>"
            data-user-groups="<?php p($user->groups) ;?>"
            data-placeholder="groups"  multiple="multiple">
               <?php foreach($_["groups"] as $group): ?>
               <option data-admin="<?php p($group->isadmin ? 1 : 0); ?>" value="<?php p($group->groupname);?>">
                  <?php p($group->groupname);?>
               </option>
               <?php endforeach;?>
            </select>
         </td>
         <td class="remove">
            <a href="#" class="action delete" title="删除">
               <img style="padding-top:5px" src="<?php print_unescaped(image_path('core', 'actions/delete.svg')) ?>" class="svg" />
            </a>
         </td>
      </tr>
      <?php endforeach; ?>
      </tbody>
      </table>
      </div>
   </div>
   <?php endif; ?>
   
   
   
</div>

<div class="resetsuburl hide"></div>
